#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maximalSquare(vector<vector<char>>& matrix) {
        int n = matrix.size(), m = matrix[0].size(), ret = 0;
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if (matrix[i - 1][j - 1] == '1')
                {
                    int tmp = sqrt(min(dp[i - 1][j], min(dp[i - 1][j - 1], dp[i][j - 1]))) + 1;
                    dp[i][j] = tmp * tmp;
                    ret = max(ret, dp[i][j]);
                }
        return ret;
    }
};